/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package r2x;

import java.sql.ResultSet;
import java.util.LinkedList;

/**
 *
 * @author przemek
 */
public class Tools {

private static char sep = '`';

public static LinkedList<String> getNamesAfterSubstring(String str, String sub){
    LinkedList <String> resultList = new LinkedList<String> ();
    int pos1 = 0,pos2 =0;
    String obtained = "";
    while (pos1 >= 0){
        pos1 = str.indexOf(sub, pos1);
        if (pos1 >= 0){
            pos1 = str.indexOf(sep, pos1)+1;
            pos2 = str.indexOf(sep,pos1);
            obtained = str.substring(pos1, pos2);
            if (! resultList.contains(obtained))
                resultList.add(obtained);
        }
    }
    return resultList;
}

public static LinkedList<String> getNamesAfterSubstring(String str, String sub, 
                                    char csep1, char csep2){
    LinkedList <String> resultList = new LinkedList<String> ();
    int pos1 = 0,pos2 =0;
    String obtained = "";
    while (pos1 >= 0){
        pos1 = str.indexOf(sub, pos1);
        if (pos1 >= 0){
            pos1 = str.indexOf(csep1, pos1)+1;
            pos2 = str.indexOf(csep2,pos1);
            obtained = str.substring(pos1, pos2);
            if (! resultList.contains(obtained))
                resultList.add(obtained);
        }
    }
    return resultList;
}

    static int getNumberOfRows(ResultSet rs) {
        int res = 0;
        try {
            while (rs.next()) {
                res++;
            }
            rs.beforeFirst();
            
        } catch (Exception e) {
            System.out.println("error while obtaining number of rows");
        }
        return res;
    }

    static String prepareSelectAllQuery(String tabName) {
        String resultQuery = "SELECT * FROM "+ tabName;
        return resultQuery;
    }

}
